package com.example.easypoi.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.easypoi.entity.DigitalElasticElement;
import com.example.easypoi.entity.DigitalPressureGauge;
import com.example.easypoi.mapper.DigitalElasticElementMapper;
import com.example.easypoi.mapper.DigitalPressureGaugeMapper;
import com.example.easypoi.service.ExcelImportService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/excelExport")
@CrossOrigin
public class ExcelExportController {

    @Resource
    private ExcelImportService excelImportService;

    @Resource
    private DigitalPressureGaugeMapper digitalPressureGaugeMapper;

    @Resource
    private DigitalElasticElementMapper digitalElasticElementMapper;

    @ResponseBody
    @PostMapping("export")
    public boolean excelExport(DigitalPressureGauge digitalPressureGauge) {
        LambdaQueryWrapper<DigitalPressureGauge> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DigitalPressureGauge::getId,digitalPressureGauge.getId());
        DigitalPressureGauge digitalPressureGauge1 =  digitalPressureGaugeMapper.selectOne(wrapper);
        digitalPressureGauge1.setData1077(digitalPressureGauge.getData1077());
        digitalPressureGauge1.setData1078(digitalPressureGauge.getData1078());
        digitalPressureGauge1.setData1079(digitalPressureGauge.getData1079());
        digitalPressureGauge1.setData1080(digitalPressureGauge.getData1080());
        digitalPressureGaugeMapper.updateById(digitalPressureGauge1);
        String s = new String();
        s =  excelImportService.templateDerive(digitalPressureGauge1);

        if (s.equals("成功")) {
            return true;
        }
            return false;

    }
    @ResponseBody
    @PostMapping("excelElasticExport")
    public boolean excelElasticExport(DigitalElasticElement digitalElasticElement) {
        LambdaQueryWrapper<DigitalElasticElement> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DigitalElasticElement::getId,digitalElasticElement.getId());
        DigitalElasticElement digitalElasticElement1 = digitalElasticElementMapper.selectOne(wrapper);
        digitalElasticElement1.setData1161(digitalElasticElement.getData1161());
        digitalElasticElement1.setData1162(digitalElasticElement.getData1162());
        digitalElasticElement1.setData1163(digitalElasticElement.getData1163());
        digitalElasticElementMapper.updateById(digitalElasticElement1);
        String s = new String();
        s =  excelImportService.exportElastic(digitalElasticElement1);

        if (s.equals("成功")) {
            return true;
        }
        return false;

    }
}
